﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Order_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetDrpDownValue();
        }
    }

    public void PopulateOrderList()
    {
        //Lv_OrderList.DataSource = Order.GetAllByCondition(0, txtJieGeFrom.Text, txtJiaGeTo.Text, txtJiFenFrom.Text, txtJiFenTo.Text, txtYunFeiFrom.Text, txtYunFeiTo.Text, txtTimeFrom.Text, txtTimeTo.Text, DongDong.Common.Misc.ConvertToInt(drpFangShi.SelectedValue), txtKey.Text, DongDong.Common.Misc.ConvertToInt(drpStatus.SelectedValue));
        Lv_OrderList.DataBind();
    }
    protected void btn_search_Click_Click(object sender, EventArgs e)
    {
        PopulateOrderList();
    }

    public void GetDrpDownValue()
    {
        drpFangShi.DataSource = DeliveryWay.GetAll();
        drpFangShi.DataValueField = "ID";
        drpFangShi.DataTextField = "Way";
        drpFangShi.DataBind();
        drpFangShi.Items.Insert(0, new ListItem("请选择", "0"));


        drpStatus.PopulateFromEnum<Order.orderstatue>();
        drpStatus.Items.Insert(0, new ListItem("请选择", "0"));
    }
    protected void Lv_OrderList_PagePropertiesChanged(object sender, EventArgs e)
    {
        PopulateOrderList();
    }
    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (Lv_OrderList.Items.Count == 0)
            PopulateOrderList();
    }
    protected void Lv_OrderList_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        Order.Delete(DongDong.Common.Misc.ConvertToInt(Lv_OrderList.DataKeys[e.ItemIndex].Value));
        PopulateOrderList();
    }

    public string ReturnAddress(object addressID)
    {
        string address = "暂无详细地址";
        //BookAddress objAddress = BookAddress.Get(DongDong.Common.Misc.ConvertToInt(addressID));
        //if (objAddress != null)
        //{
        //    address = objAddress.Detail;
        //}
        return address;
    }

    public string ReturnFangShi(object wayID)
    {
        string way = "暂无发货方式";
        DeliveryWay objWay = DeliveryWay.Get(DongDong.Common.Misc.ConvertToInt(wayID));
        if (objWay != null)
        {
            way = objWay.Way;
        }
        return way;
    }

    public string ReturnUserName(object UserID)
    {
        string UserName = "暂无信息";
        Client objClient = Client.Get(DongDong.Common.Misc.ConvertToInt(UserID));
        if (objClient != null)
        {
            UserName = objClient.Username ?? "";
        }
        return UserName;
    }
}